package com.cdtye.shuoh.controller.product;

import com.cdtye.common.webcore.web.AjaxJson;
import com.cdtye.shuoh.domain.product.vo.ProductVo;
import com.cdtye.shuoh.service.product.ProductService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 产品Controller
 * @author ZhongWang Wang
 * @date 2022-12-21
 */

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     *导入产品模型json数据
     * @param file
     * @return
     */
    @PostMapping("/importProductJsonFile")
    public AjaxJson importProductJsonFile(MultipartFile file) throws Exception {

        return productService.importProductJsonFile(file);
    }

    /**
     * 分页查询
     * @param vo
     * @return
     */
    @PostMapping("/pageList")
    public AjaxJson pageList(@RequestBody ProductVo vo){
        return AjaxJson.success(productService.pageList(vo));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/getById")
    public AjaxJson getById(String id){
        return AjaxJson.success(productService.getById(id));
    }

    /**
     * 修改产品信息
     * @param vo
     * @return
     */
    @PostMapping("/updateProduct")
    public AjaxJson updateProduct(@RequestBody ProductVo vo){
        return AjaxJson.success(productService.updateProduct(vo));
    }

    /**
     * 获取产品列表
     * @param vo
     * @return
     */
    @PostMapping("/selectList")
    public AjaxJson selectList(@RequestBody ProductVo vo){
        return AjaxJson.success(productService.selectList(vo));
    }

    /**
     * 根据id删除产品
     * @param id
     * @return
     */
    @GetMapping("/deleteById")
    public AjaxJson deleteById(String id){
        return AjaxJson.success(productService.deleteById(id));
    }

    @GetMapping("/stateStatistic")
    public AjaxJson stateStatistic(){
        return AjaxJson.success(productService.stateStatistic());
    }

}
